package com.hdit.action.admin;

import javax.annotation.Resource;

import com.hdit.entity.Member;
import com.hdit.entity.MemberShili;
import com.hdit.service.MemberService;
import com.hdit.service.MemberShiliService;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.BeanUtils;

import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

/**
 * 后台Action类 - 会员视力档案
 * ============================================================================
 */

@ParentPackage("admin")
public class MemberShiliAction extends BaseAdminAction {

	private static final long serialVersionUID = -5451875129461788865L;

	private MemberShili memberShili;
	
	private String memberId;

	@Resource
	private MemberShiliService memberShiliService;
	
	@Resource
	private MemberService memberService;

	
	// 列表
	public String list() {
		pager = memberShiliService.findByPager(pager);
		return LIST;
	}

	// 删除
	public String delete() {		
		memberShiliService.delete(ids);
		return ajaxJsonSuccessMessage("删除成功！");
	}

	// 添加
	public String add() {
		
		if(this.getMemberId()==null||this.getMemberId().trim().equals("")){			
			return ERROR;
		}
		else{
			Member member = memberService.load(this.getMemberId());
			if(member==null){
				return ERROR;
			}
			else{
				return INPUT;
			}
		}
		
	}

	// 编辑
	public String edit() {
		memberShili = memberShiliService.load(id);
		
		//this.memberId=memberShili.getMember().getId();
		
		return INPUT;
	}

	// 保存
	
	@InputConfig(resultName = "error")
	public String save() {		
		
		if(this.getMemberId()==null||this.getMemberId().trim().equals("")){			
			return ERROR;
		}
		else{
			Member member = memberService.load(this.getMemberId());
			if(member==null){
				return ERROR;
			}
			else{
				memberShili.setMember(member);
				memberShiliService.save(memberShili);
				redirectionUrl = "member_shili!list.action";
				return SUCCESS;
			}
		}
		
		
	}

	// 更新
	
	@InputConfig(resultName = "error")
	public String update() {
		
		MemberShili persistent = memberShiliService.load(id);
		
		
		if(this.getMemberId()==null||this.getMemberId().trim().equals("")){			
			return ERROR;
		}
		else{
			Member member = memberService.load(this.getMemberId());
			if(member==null){
				return ERROR;
			}
			else{
				memberShili.setMember(member);
				BeanUtils.copyProperties(memberShili, persistent, new String[] {"id", "createDate", "modifyDate"});

				memberShiliService.update(persistent);
				redirectionUrl = "member_shili!list.action";
				return SUCCESS;
			}
		}
		
		
	}

	public MemberShili getMemberShili() {
		return memberShili;
	}

	public void setMemberShili(MemberShili memberShili) {
		this.memberShili = memberShili;
	}

	public String getMemberId() {
		return memberId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

}